import { Injectable } from '@angular/core';
import { ApiService, JsonResult } from './api.service';
import { map } from 'rxjs/operators';
import { NzIconModule } from 'ng-zorro-antd/icon';

import {
   AddVo, TokenVo, DeleteTokenVo
  } from 'src/app/shared/models';
import { post } from 'selenium-webdriver/http';

@Injectable({
  providedIn: 'root'
})
export class TokenService {
    constructor(
        private apiService: ApiService
      ) { }

// idap 配置新增
addIdapConfig(postData: any) {
    return this.apiService.get('', postData).pipe(
      map((jsonResult: JsonResult<AddVo>) => jsonResult)
    );
  }

  // 新增token
  addToken (postData: any) {
    console.log('resData', postData);
    return this.apiService.post('/api/user/token', postData).pipe(
      map((jsonResult: JsonResult<TokenVo>) => jsonResult)
    );
  }

   // 重置token
   refreshToken () {
    return this.apiService.put('/api/user/token/refresh').pipe(
      map((jsonResult: JsonResult<TokenVo>) => jsonResult)
    );
  }
   // 重新更新token时间
   refreshTokenTime (postData: any) {
    return this.apiService.put('/api/user/token', postData).pipe(
      map((jsonResult: JsonResult<TokenVo>) => jsonResult)
    );
  }
    // 查询token
    getTokenInfo () {
      return this.apiService.get('/api/user/token').pipe(
        map((jsonResult: JsonResult<TokenVo>) => jsonResult)
      );
    }

     // 删除token
   deleteToken () {
    return this.apiService.delete('/api/user/token').pipe(
      map((jsonResult: JsonResult<DeleteTokenVo>) => jsonResult)
    );
  }
}
